package cn.edu.zut.dao;

import cn.edu.zut.domin.BookLendInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IBookLendInfoDao {

    /**
     * 查找所有图书信息
     * @return
     */
    @Select("SELECT * FROM  BookLendInfo")
    public List<BookLendInfo> findAll();


    /**
     * 插入图书借阅信息
     * @param bookLendInfo
     */
    @Insert("insert into  BookLendInfo(bookId,readerId,lendNumber,lendDate,dueReturnDate,actualReturnDate,fineAmount) values (#{bookId},#{readerId},#{lendNumber},#{lendDate},#{dueReturnDate},#{actualReturnDate},#{fineAmount})")
    public void insertBookLendInfo(BookLendInfo bookLendInfo);
    /**
     * 根据读者ID来查找借阅信息
     * @param readerId
     * @return
     */
    @Select("select * from BookLendInfo where readerId=#{readerId} ")
    public List<BookLendInfo> getBookLendInfoByReaderId(String readerId);

    /**
     * 根据图书ID来查找借阅信息
     * @param bookId
     * @return
     * */
     @Select("select * from BookLendInfo where bookId=#{bookId}")
     public List<BookLendInfo> getBookLendInfoByBookId(String bookId);

    /**
     * 删除借阅信息(参数两个或者以上需要@Param，否则mybatis无法识别)
     * @param bookId
     * @param readerId
     */
    @Delete("delete from BookLendInfo where bookId=#{bookId} and  readerId=#{readerId}")
    public void delectBookLendInfo(@Param("bookId") String bookId, @Param("readerId") String readerId);

    /**
     * 更新图书信息
     * @param bookLendInfo
     */
    @Update("update BookLendInfo set bookId=#{bookId},readerId=#{readerId},lendNumber=#{lendNumber},lendDate=#{lendDate},dueReturnDate=#{dueReturnDate}," +
            "actualReturnDate=#{actualReturnDate},fineAmount=#{fineAmount} where bookId=#{bookId} and readerId=#{readerId}")
    public void setNewInfo(BookLendInfo bookLendInfo);

    /**
     * 根据读者和图书查询借阅信息
     * @param bookId
     * @param readerId
     * @return
     */
    @Select("select * from BookLendInfo where bookId=#{bookId} and readerId=#{readerId}")
    public List<BookLendInfo> getBookLendInfoByBookIdAndReaderId(@Param("bookId") String bookId, @Param("readerId") String readerId);


}
